<template>
	<view class="shop_list">
		<view class="shop_item">
			<image src="../../static/images/background.png" mode="aspectFit"></image>
			<view class="shop_item_title">
				唐制齐胸杉裙
			</view>
			<view class="shop_item_bottom">
				<text>200</text>
				<text>购物车</text>
			</view>
		</view>
		<!-- <uni-list>
			<view v-for="(item,index) in shopList" :key="item._id" style="margin-top: 40rpx;" @click="goDetail(item)">
				<text style="margin-right: 20rpx;">{{item.shopName}}</text>
				<text style="margin-right: 20rpx;">{{item.shopCode}}</text>
				<text style="margin-right: 20rpx;">{{item.shopPrice}}元</text>
				<view class="" v-if="item.imageUrls.length > 0"> 
					<image :src="url" mode="aspectFit" v-for="(url,index) in item.imageUrls" :key="index"></image>
				</view>
			
			</view>
		</uni-list>
		<view class="bottom" v-if="limit">
			到底了
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shopList: [],
				searchParams:{
					page:0,
					limit:20
				},
				limit:false,
				isShowNodata:true
			}
		},
		onLoad() {
			this.searchParams.page = 0
			this.searchParams.limit = 20
			this.shopList = []
			this.getList()
		},
		onPullDownRefresh() {
			this.limit = false
			this.searchParams.page = 0 
			this.isShowNodata = false
			this.shopList = []
			setTimeout(() =>{
				this.getList()
			},800)
		},
		
		// 下来加载
		onReachBottom() {
			if(this.limit) return
			this.searchParams.page += 1
			this.getList()
		},
		methods:{
			//获取商品列表数据
			getList() {	
				uniCloud.callFunction({
					name: 'getShop',
					// 获取列表数据
					data: this.searchParams,
					success: (res) => {
						console.log('成功了', res)
						if(res.result.data.length < 20 ){
							this.limit = true
						}
						this.shopList =  this.shopList.concat(res.result.data)
						this.isShowNodata = true
						uni.stopPullDownRefresh();
					},
					fail: (err) => {
						console.log('失败了', err)
					}
				})
			},
			goDetail(item){
				console.log('item',item._id)
				uni.navigateTo({
					url:`./shopInfo?shopId=${item._id}`
				})
				
			}
		}
	}
</script>

<style>
</style>
